typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;

typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef long long int64;

#define VOS_OK                          0
#define VOS_ERROR                       1
#define VOS_ERROR_START                 1000 

#define VOS_OS_ERR_START                (VOS_ERROR_START)		/*1000-1499*/
#define VOS_NETWORK_ERR_START           (VOS_ERROR_START + 500)		/*1500-2499*/
#define VOS_PTHREAD_ERR_START           (VOS_NETWORK_ERR_START + 1000)	/*2500-2999*/		
#define VOS_USR_ERR_START               (VOS_PTHREAD_ERR_START + 500)	/*3000-3999*/
#define VOS_SQL_ERR_START               (VOS_USR_ERR_START + 1000)	/*4000-4999*/
#define VOS_ROUTE_ERR_START             (VOS_SQL_ERR_START + 1000)	/*5000-*/

#define VOS_OS_ERR_MALLOC_FAIL                          (VOS_OS_ERR_START + 1)
/*begin: add by wangtianyu for mem 201201123*/
#define VOS_OS_ERR_MALLOC_FAIL                          (VOS_OS_ERR_START + 1)
#define VOS_OS_ERR_POINTER_NULL                         (VOS_OS_ERR_START + 2)
#define VOS_OS_ERR_MALLOC_PAGE_FAIL                     (VOS_OS_ERR_START + 3)
#define VOS_OS_ERR_MALLOC_BLOCK_FAIL                    (VOS_OS_ERR_START + 4)
#define VOS_OS_ERR_MEM_BLOCK_MIN_FULL                   (VOS_OS_ERR_START + 5)
#define VOS_OS_ERR_MEM_BLOCK_LESS_FULL                  (VOS_OS_ERR_START + 6)
#define VOS_OS_ERR_MEM_BLOCK_MORE_FULL                  (VOS_OS_ERR_START + 7)
#define VOS_OS_ERR_MEM_BLOCK_MAX_FULL                   (VOS_OS_ERR_START + 8)
#define VOS_OS_ERR_MEM_LOOP_FULL                        (VOS_OS_ERR_START + 9)
#define VOS_OS_ERR_MEM_MALLOC_NO_OK                     (VOS_OS_ERR_START + 10)
#define VOS_OS_ERR_MEM_INIT_NO_OK                       (VOS_OS_ERR_START + 11)
#define VOS_OS_ERR_MEM_MALLOC_SIZE_INVAILD              (VOS_OS_ERR_START + 12)
#define VOS_OS_ERR_MEM_NODE_SIZE_ZERO                   (VOS_OS_ERR_START + 13)
/*end: add by wangtianyu for mem 201201123*/

#define VOS_NETWORK_ERR_CONNECT_FAIL                    (VOS_NETWORK_ERR_START + 1)
#define VOS_NETWORK_ERR_NET_VIO_ERR                     (VOS_NETWORK_ERR_START + 2)
#define VOS_NETWORK_ERR_POINTER_NULL                    (VOS_NETWORK_ERR_START + 3) 

#define VOS_PTHREAD_ERR_ID_INVAILD                      (VOS_PTHREAD_ERR_START + 1)
#define VOS_PTHREAD_ERR_PTHREAD_NUM_OVER                (VOS_PTHREAD_ERR_START + 2) 
#define VOS_PTHREAD_ERR_PTHREAD_FREE_LINK_EMPTY         (VOS_PTHREAD_ERR_START + 3) 
#define VOS_PTHREAD_ERR_PTHREAD_READY_LINK_EMPTY        (VOS_PTHREAD_ERR_START + 4) 
#define VOS_PTHREAD_ERR_PTHREAD_POINTER_NULL            (VOS_PTHREAD_ERR_START + 5) 
#define VOS_PTHREAD_ERR_PTHREAD_NUM_OVERRUN             (VOS_PTHREAD_ERR_START + 6) 

#define VOS_SQL_ERR_POINTER_NULL                        (VOS_SQL_ERR_START + 1) 
#define VOS_SQL_ERR_DB_IS_NOT_EXIST                     (VOS_SQL_ERR_START + 2) 
#define VOS_SQL_ERR_TABLE_IS_NOT_EXIST                  (VOS_SQL_ERR_START + 3) 
#define VOS_SQL_ERR_TABLE_HASH_MOD_INVAILD              (VOS_SQL_ERR_START + 4)
#define VOS_SQL_ERR_TABLE_INCLU_STRING                  (VOS_SQL_ERR_START + 5) 
#define VOS_SQL_ERR_INVAILD_KEY_RELATION                (VOS_SQL_ERR_START + 6) 
#define VOS_SQL_ERR_TABLE_HASH_MOD_OVERRUN              (VOS_SQL_ERR_START + 7)
#define VOS_SQL_ERR_MORE_CHILD_DB                       (VOS_SQL_ERR_START + 8)
#define VOS_SQL_ERR_KEY_TYPE_ERR                        (VOS_SQL_ERR_START + 9)
#define VOS_SQL_ERR_TABLE_NAME_ERR                      (VOS_SQL_ERR_START + 10)
#define VOS_SQL_ERR_DB_IS_NOT_USED                      (VOS_SQL_ERR_START + 11) 
#define VOS_SQL_ERR_VALUE_INVAILD                       (VOS_SQL_ERR_START + 12) 
#define VOS_SQL_ERR_SQL_LENGTH_INVAILD                  (VOS_SQL_ERR_START + 13) 

/*BEGIN add by oxwf 2012-11-14*/
#define VOS_SQL_ERR_NO_KEY                              (VOS_SQL_ERR_START + 101)//sql语句中查询不到主键
#define VOS_SQL_ERR_GRAMMAR	                        (VOS_SQL_ERR_START + 102)//where子句中犯的语法错误返回这个
#define VOS_SQL_ERR_NO_KEY_COL				(VOS_SQL_ERR_START + 103)//在insert语句中使用，查询不到主键所在的列号
#define VOS_SQL_ERR_NO_SUPPORT                          (VOS_SQL_ERR_START + 104)//不支持这种sql语句
/*END add by oxwf 2012-11-14*/

#define MAX_UINT32_VALUE     0xFFFFFFFF
#define MAX_UINT16_VALUE     0xFFFF
#define MAX_UINT8_VALUE      0xFF

#define HASH_MOD  4 
#define DB_NUM    3

/*每个分库 的最大链接数*/
#define MAX_CHILD_DB_THREAD_NUM (2 + 1)
/*每个数据库 的最大链接数*/
#define MAX_DB_THREAD_NUM (HASH_MOD * MAX_CHILD_DB_THREAD_NUM)
/*整个中间件 的最大链接数*/
#define THREAD_ELEM_NUM  (DB_NUM * MAX_DB_THREAD_NUM + 20)

/*begin 数据库配置信息*/

#define TABLE_NAME_LENGTH 32
#define KEY_NAME_LENGTH 32

#define IP_ADDRESS_LENGTH 15
#define DB_ADMIN_NAME_LENGTH 15
#define DB_ADMIN_PWD_LENGTH 15

#define DB_NAME_LENGTH 15
#define TABLE_NUM 100

/*end  数据库配置信息*/

#define HASH_MOD_STRING_LENGTH 10

#define KEY_VALUE_LENGTH 32
#define KEY_MAX_NUM      10

/**/
#define MAX_SQL_RESULT_SIZE       (4 * 1024)
#define MAX_CACHE_SQL_RESULT_NUM  8

#define MYSQL_RESULT_HEAD_SIZE    18
#define MYSQL_RESULT_FIELD_SIZE   1024
#define MYSQL_RESULT_ROW_SIZE   (1024)
#define MYSQL_GET_READY_TIMES   5
#define MYSQL_READY_LINK_NUM    5
/**/

/*begin: add by wangtianyu for mem 201201123*/
#define MEM_NODE_MIN_SIZE     256
#define MEM_NODE_LESS_SIZE    1024
#define MEM_NODE_MORE_SIZE    (1024 * 8)
#define MEM_NODE_MAX_SIZE     (1024 * 256)
#if 0
#define MEM_NODE_MIN_NUM      65536
#define MEM_NODE_LESS_NUM     6144
#define MEM_NODE_MORE_NUM     1024
#define MEM_NODE_MAX_NUM      8
#endif
#define MEM_NODE_MIN_NUM      40 
#define MEM_NODE_LESS_NUM     10 
#define MEM_NODE_MORE_NUM     5 
#define MEM_NODE_MAX_NUM      2

#define MEM_PAGE_HEAD_SIZE    sizeof(st_MEM_Page_M)
#define MEM_BLOCK_HEAD_SIZE   sizeof(st_MEM_Block_M)
#define MEM_NODE_HEAD_SIZE    sizeof(st_MEM_Node_M)
#define MEM_POINT_SIZE        sizeof(void *)


#define MEM_NODE_MIN_TYPE     1
#define MEM_NODE_LESS_TYPE    2
#define MEM_NODE_MORE_TYPE    3
#define MEM_NODE_MAX_TYPE     4

#define MEM_MAX_PAGE_NUM      32
#define MEM_INIT_PAGE_NUM     2
#define MAX_CACHE_ROW_RESULTS 10
/*end: add by wangtianyu for mem 201201123*/

/*某库的中指定表的信息*/
typedef struct st_Table_m {
    char table_name[TABLE_NAME_LENGTH + 1]; /*表名*/
    char key_name[KEY_NAME_LENGTH + 1]; /*主键名称*/

    uint8 table_hash_mod; /*该表拆分情况*/
    uint8 key_type; /*主键类型1:字符串2:数字*/
    uint8 key_col; /*主键所在列*/

    uint8 reserved1;
    uint8 reserved2;
    uint8 reserved3;

} st_Table_m;

/*某库的分库信息*/
typedef struct st_ChildDbInfo {
    char child_db_name[DB_NAME_LENGTH + 1]; /*数据库分库名称*/
    char host[IP_ADDRESS_LENGTH + 1]; /*中间件连接DB的IP*/
    uint port; /*中间件连接DB的port*/

    char user[DB_ADMIN_NAME_LENGTH + 1]; /*中间件连接DB的user */
    char pwd[DB_ADMIN_PWD_LENGTH + 1]; /*中间件连接DB的pwd*/
    ulong client_flag;

    char used; /*是否使用，0：未使用，1使用*/
    uint8 reserved1;
    uint8 reserved2;
    uint8 reserved3;

} st_child_DBInfo;

/*数据库基本信息，系统启动需要初始化*/
typedef struct st_DbInfo {
    char db_name[DB_NAME_LENGTH + 1]; /*数据库名称*/
    uint8 db_id; /*数据库ID*/
    uint8 db_hash_mod; /*数据库最大hash取模*/

    char used; /*是否使用，0：未使用，1使用*/
    uint8 reserved1;

    st_Table_m table_list[TABLE_NUM]; /*库中的原表信息数组，即有多少张表*/
    st_child_DBInfo child_DbInfo_list[HASH_MOD]; /*分库信息*/
} st_DBInfo;
st_DBInfo st_DB_Info[16];

/*end  数据库配置信息*/
union sql_key_value {
    uint32 key_value_int[KEY_MAX_NUM];
    char key_value_str[KEY_MAX_NUM][KEY_VALUE_LENGTH + 1];
    float key_value_float[KEY_MAX_NUM];
    double key_value_double[KEY_MAX_NUM];
};

